##@brief all things to do with twitter are using this file
import tweepy
from dbconnect import MainDBConnector

dbc = MainDBConnector('twitter.db')

##class to wrap tweepy
class Api():
	def __init__(self, consumer_key, consumer_secret):
		"""!initializing with consumer key
		@param consumer_key consumer_key
		@param consumer_secret consumer_secret
		"""
		self._consumer_key = consumer_key
		self._consumer_secret = consumer_secret
	
	def userLogin(self, access_token, access_secret):
		auth = tweepy.OAuthHandler(self._consumer_key, self._consumer_secret)
		auth.set_access_token(access_token, access_secret)
		api = tweepy.API(auth)
		return User(api)

class User():
	def __init__(self, api):
		self._api = api
		me = self._api.me()
		self.screenname = me.screen_name
		self.userid = me.id
	
	def getMentions(self):
		last_mentionid = dbc.getLastMention(self.userid)
		mentions = self._api.mentions(last_mentionid)
		return mentions
	def setLastMention(self, mentionid):
		dbc.setLastMention(self.userid, mentionid)
	
	def replyTo(self, mentionid, reply_string):
		self._api.update_status(reply_string, mentionid)
